<?php
require_once 'models/newconnect.php';

class usersModel {
    public $con;
    public function __construct(){
        $this->con=mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
        if (mysqli_connect_errno())
        {
            echo "Failed to connect to MySQL: " . mysqli_connect_error();	exit();
        }
    }
    //Method get lists users from database
    public function getListUsers(){
        $query = "SELECT * FROM user ";
        $users = mysqli_query($this->con,$query);
        return $users;
    }
    // Method get user along ID
    public function getUser($id)
    {
        $query="SELECT * FROM user where id='$id'";
        $result = mysqli_query($this->con,$query);
        $row = mysql_affected_rows($result);
        return $row;
    }
    //Method add
    public  function  addUser($f_name, $l_name, $email, $password, $priority){

        $f_name = mysql_escape_string(trim($f_name));
        $l_name = mysql_escape_string(trim($l_name));
        $email = mysql_escape_string(trim($email));
        $password = mysql_escape_string(trim($password));
        $priority = mysql_escape_string(trim($priority));
     //   mysqli_query($this->con, "INSERT INTO user (f_name,l_name,email,pass,priority) VALUE ('1','2','3','4','5')");
        mysqli_query($this->con, "INSERT INTO USER (f_name,l_name,email,pass,priority) VALUE ('$f_name','$l_name','$email','$password','$priority')");
    }
    // Method delete
    public function deleteUser($id){
        mysqli_query($this->con, "DELETE  FROM USER WHERE id = '$id'");
    }
}